#ifndef _ICOMBASE_H_
#define _ICOMBASE_H_

#include <dlcom/unknown.h>

namespace StdCom
{

interface ICreator : public IBase
{
    std_method(CreateInstance)(REFCLSID clsid, IBase* punk, REFIID iid, void** ppv) PURE;
    std_method_(LPCSTR, ProgIDFromCLSID)(REFCLSID clsid) PURE;
    std_method_(CLSID, CLSIDFromProgID)(LPCSTR progid) PURE;
};

interface ILibManager : public IBase
{
    std_method(Load)(LPSTRING path, LPCSTR name) PURE;
    std_method(Remove)(LPCSTR name) PURE;
    std_method(Free)() PURE;
    std_method_(DWORD, GetCount)() PURE;
    std_method(Get)(LPCSTR name, basic_tchar* path, int len) PURE;
    std_method(Register)(SafeStringConstPtr name, UINT type, UINT version) PURE;
    std_method(UnRegister)(SafeStringConstPtr name, UINT type, UINT version) PURE;
    std_method(Registers)(UINT type, UINT version) PURE;
    std_method(UnRegisters)(UINT type, UINT version) PURE;
};

// {E670ECA1-E73C-4EE7-92D6-42C597254A38}
_DEF_IID(IID_ICreator, 0xe670eca1, 0xe73c, 0x4ee7, 0x92, 0xd6, 0x42, 0xc5, 0x97, 0x25, 0x4a, 0x38);

// {619CDF0D-DEA4-4A4E-8774-D2D51BE0B208}
_DEF_IID(IID_ILibManager, 0x619cdf0d, 0xdea4, 0x4a4e, 0x87, 0x74, 0xd2, 0xd5, 0x1b, 0xe0, 0xb2, 0x8);

// {6D9D2CF3-276A-426e-9041-FB5428DE44B1}
_DEF_CLSID(CLSID_CLoader, 0x6d9d2cf3, 0x276a, 0x426e, 0x90, 0x41, 0xfb, 0x54, 0x28, 0xde, 0x44, 0xb1);

interface IRot : public IBase
{
    std_method(CreateInstance)(REFCLSID clsid, IBase* punk, REFIID iid, void** ppv) PURE;
    std_method(Register)(REFCLSID clsid, LPCSTR progid, IBase* punk, ULONG id) PURE;
    std_method(Revoke)(REFCLSID clsid) PURE;
    std_method(IsRunning)(REFCLSID clsid) PURE;
    std_method(GetObject)(REFCLSID clsid, REFCLSID iid, IBase** ppunk) PURE;
    std_method(RevokeAll)() PURE;
    std_method_(LPCSTR, ProgIDFromCLSID)(REFCLSID clsid) PURE;
    std_method_(CLSID, CLSIDFromProgID)(LPCSTR progid) PURE;
    std_method_(ULONG, GetObjectCount)() PURE;
};

// {08F56552-D015-4C3B-B984-2211A4F880FF}
_DEF_IID(IID_IRot, 0x8f56552, 0xd015, 0x4c3b, 0xb9, 0x84, 0x22, 0x11, 0xa4, 0xf8, 0x80, 0xff);

// {513F39CB-04C7-4068-82DA-FAFE689D5EE4}
_DEF_CLSID(ClSID_CRot, 0x513f39cb, 0x4c7, 0x4068, 0x82, 0xda, 0xfa, 0xfe, 0x68, 0x9d, 0x5e, 0xe4);

#define OBJECT_RUN_RET_SUCCESS  0
#define OBJECT_RUN_RET_ERROR    1000
#define OBJECT_RUN_RET_RESTART  1001
#define OBJECT_RUN_RET_FAILD    2000
#define OBJECT_RUN_RET_NULL     2001
#define OBJECT_RUN_RET_CLSIDERR 2002
#define OBJECT_RUN_RET_COMPERR  2003
#define OBJECT_RUN_RET_FILEERR  2004
#define OBJECT_RUN_RET_MEMERR   2005
#define OBJECT_RUN_RET_ROTERR   2006
#define OBJECT_RUN_RET_PARAMERR 2007
#define OBJECT_RUN_RET_STARTERR 2008

interface IExit : public IBase
{
    std_method(OnExit)(UINT uExit) PURE;
    std_method_(UINT, GetExitCode)() PURE;
};

// {70B0D10B-463F-496A-90A5-F22175F77A1D}
_DEF_IID(IID_IExit, 0x70b0d10b, 0x463f, 0x496a, 0x90, 0xa5, 0xf2, 0x21, 0x75, 0xf7, 0x7a, 0x1d);

#define STD_INIT  0x01
#define STD_START 0x02
#define STD_MSG   0x04

#define STD_ROT 0x10
#define STD_VEC 0x20

#define STD_COMPOENT (STD_VEC | STD_ROT)

#define ROT_ID     1000
#define ROT_LOAD   ROT_ID + 1
#define ROT_UNLOAD ROT_ID + 2

interface IObjectRun : public IBase
{
    std_method(SetMainRun)(IBase* pBase) PURE;
    std_method(SetClsid)(REFCLSID clsid) PURE;
    std_method_(CLSID, GetClsid)() PURE;
    std_method(LoadConf)(const SafeStringPtr* code) PURE;
    std_method_(LPCSTR, GetConf)() PURE;
    std_method(Register)(SafeStringConstPtr name, UINT type, UINT version) PURE;
    std_method(UnRegister)(SafeStringConstPtr name, UINT type, UINT version) PURE;
    std_method(Registers)(UINT type, UINT version) PURE;
    std_method(UnRegisters)(UINT type, UINT version) PURE;
    std_method(SetPath)(const SafePStringPtr* path) PURE;
    std_method_(LPSTRING, GetPath)() PURE;
    std_method(Load)() PURE;
    std_method(Init)(_pid_t pid, basic_tchar* argv[], int argc) PURE;
    std_method(Start)(UINT type) PURE;
    std_method(Stop)(UINT type, UINT exit) PURE;
    std_method_(UINT, Run)(UINT type) PURE;
    std_method(Exit)(UINT exit) PURE;
    std_method(Uninit)() PURE;
    std_method(Clear)() PURE;
    std_method(GetRotPlugin)(IBase** pBase) PURE;
    std_method(GetMsgPlugin)(IBase** pBase) PURE;
    std_method(GetLoaderPlugin)(IBase** pBase) PURE;
    std_method(GetMainRunPlugin)(IBase** pBase) PURE;
    std_method(AddObject)(REFCLSID clsid, LPCSTR progid, IBase* pBase, ULONG index, LPCSTR container, UINT type) PURE;
    std_method_(CLSID, GetRunPluginCLSID)() PURE;
    std_method_(ULONG, GetRunPluginsCount)() PURE;
    std_method_(ULONG, GetRunIndex)(ULONG index) PURE;
    std_method_(UINT, GetExitCode)() PURE;
    std_method_(UINT, GetArgc)() PURE;
    std_method_(LPSTRING, GetIndexArgc)(UINT index) PURE;
    std_method_(UINT, GetStartType)() PURE;
    std_method_(_pid_t, get_instance)() PURE;
};

// {321B84B2-ACE3-4EC4-9E0C-A63870839F07}
_DEF_IID(IID_IObjectRun, 0x321b84b2, 0xace3, 0x4ec4, 0x9e, 0xc, 0xa6, 0x38, 0x70, 0x83, 0x9f, 0x7);

// {7DADD097-97B4-45ec-A04C-135604FB6934}
_DEF_CLSID(CLSID_CObjectRun, 0x7dadd097, 0x97b4, 0x45ec, 0xa0, 0x4c, 0x13, 0x56, 0x4, 0xfb, 0x69, 0x34);

interface IMainRun : public IBase
{
    std_method(CreateObject)(REFCLSID rid, IBase** pIObjectRun, SafePStringConstPtr path, SafeStringConstPtr code) PURE;
    std_method_(int, IsObjectExist)(REFCLSID rid) PURE;
    std_method(GetObjectRun)(REFCLSID rid, IBase** pIObjectRun) PURE;
    std_method(GetObject)(REFCLSID rid, REFCLSID clsid, REFCLSID iid, IBase** ppunk) PURE;
    std_method(FreeObject)(REFCLSID id, UINT exit) PURE;
    std_method(Free)(UINT exit) PURE;
    std_method(SendMsg)(REFCLSID rid, REFCLSID gn, REFCLSID sn, REFCLSID tn, UINT msg, IBase* inmsg, IBase** outmsg) PURE;
    std_method(SendBroadcastMsg)(REFCLSID gn, REFCLSID sn, REFCLSID tn, UINT msg, IBase* inmsg) PURE;
};

// {8902BA7D-F254-4455-92A3-98FF5BD85AAA}
_DEF_IID(IID_IMainRun, 0x8902ba7d, 0xf254, 0x4455, 0x92, 0xa3, 0x98, 0xff, 0x5b, 0xd8, 0x5a, 0xaa);

// {F48B2086-61E9-4F4E-AE1D-330B501E358A}
_DEF_CLSID(CLSID_CMainRun, 0xf48b2086, 0x61e9, 0x4f4e, 0xae, 0x1d, 0x33, 0xb, 0x50, 0x1e, 0x35, 0x8a);

} // namespace StdCom

#endif
